#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif

WiFiClient espClient;
PubSubClient client(espClient);
#ifndef AP_CONFIG
String UID = {{&clientId}};
#endif
const char* UserName = {{&userName}};
const char* PassWord = {{&password}};
bool subTopicCenterFlag = false;
unsigned long bemfa_mqtt_current_millis;
unsigned long bemfa_mqtt_last_re_millis = 0;
void reConnect() {
  if (!client.connected()) {
    if (client.connect(UID.c_str(), UserName, PassWord)) {
      Serial.println("connected");
      subTopicCenterFlag = true;
    } else {
      bemfa_mqtt_current_millis = millis();
      if (bemfa_mqtt_current_millis - bemfa_mqtt_last_re_millis > 2000) { 
        bemfa_mqtt_last_re_millis = millis();
        Serial.println(" try again reconnect");
        #ifdef ESP32
        WiFi.begin();
        #endif
      }
    }
  }
}